#include<ros/ros.h>



int main(int argc, char *argv[])
{
    
    setlocale(LC_ALL,"");
    ros::init(argc,argv, "get_para_c");

    ros::NodeHandle nh;

    //1.param
    float radius = nh.param("radius",0.5);
    ROS_INFO("radius = %.2f",radius);

    //2.getParam

    double radius2 = 0.0;
    bool result = nh.getParam("radius",radius2);
    if(result){
        ROS_INFO("获取的半径是:%.2f",radius2);
    }else{
        ROS_INFO("被查询的变量不存在"); 
    }

    //3.getParamCached 适用于高性能场景
    
    result = nh.getParamCached("radius2",radius2);
    if(result){
        ROS_INFO("获取的半径是:%.2f",radius2);
    }else{
        ROS_INFO("被查询的变量不存在"); 
    }
    //4.getParamNames 
    std::vector<std::string> names;
    nh.getParamNames(names);
    
    for(int i = 0;i<names.size();i++){
        
        ROS_INFO("遍历的元素:%s", names.at(i).c_str()); 
    }

    //5.hasParam
    bool flag1 = nh.hasParam("radius");
    bool flag2= nh.hasParam("radiusxxx");
    ROS_INFO("radius 存在嘛? %d",flag1);
    ROS_INFO("radiusxxx 存在嘛？ %d",flag2);

    //6.searchParam
    std::string key;
    nh.searchParam("radius", key);
    ROS_INFO("搜索结果:%s",key.c_str());

    //ros::param
    double radius_param = ros::param::param("radius",100.5);
    ROS_INFO("radius_param = %.2f",radius_param);

    std::vector<std::string> names_param;
    ros::param::getParamNames(names_param);
    for(int i = 0;i<names_param.size();i++){
        ROS_INFO("键：%s",names_param.at(i).c_str());
    }


    return 0;
}
